package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired(required = false)
    private UserService userService;

    @PostMapping("/login")
    public void login(@RequestBody Map<String,String> param){
        String phone = param.get("phone");
        userService.sendMsg(phone);
    }

    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> param){
        String phone = param.get("phone");
        String verificationCode = param.get("verificationCode");
        Map<String,Object> map = userService.veryfyCode(phone,verificationCode);
        return ResponseEntity.ok(map);
    }
}
